package com.zbxx.practice.jdbcpool;

import org.slf4j.LoggerFactory;

import java.io.FileInputStream;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

/**
 * @author 万仁杰
 * @date 2019/05/27
 */

public class ConnectionConfig  {

    private static org.slf4j.Logger logger = LoggerFactory.getLogger(DataSourcePool.class);


    private static String url;

    private static String username;

    private static String password;

    private static String driver;

    static {
        Properties properties = new Properties();
        try {
            properties.load(new FileInputStream("E:\\ideaworkspace\\container\\testproject\\src\\main\\resources\\application.properties"));
        } catch (IOException e) {
            logger.error("资源文件没找到");
        }
        url = properties.getProperty("jdbc.url");
        username = properties.getProperty("jdbc.username");
        password = properties.getProperty("jdbc.password");
        driver = properties.getProperty("jdbc.driver");
        try {
            Class.forName(driver);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    public static Connection getConnection() throws SQLException, ClassNotFoundException {
        Connection connection = DriverManager.getConnection(url,username,password);
        return connection;
    }

  
}

